import {
    setStore,
    getStore,
    removeStore
} from '@/util/store'
import website from '@/config/website'
import { showYear } from '@/config/env'
const common = {
    state: {
        language: getStore({ name: 'language' }) || 'zh',
        isCollapse: false,
        isFullScren: false,
        isMenu: true,
        isRefresh: true,
        screen: -1,
        isLock: getStore({ name: 'isLock' }),
        colorName: getStore({ name: 'colorName' }) || '#09ad89',
        themeName: getStore({ name: 'themeName' }) || 'theme-white',
        lockPasswd: getStore({ name: 'lockPasswd' }) || '',
        website: website,
        showYear: getStore({ name: 'showYear' }) || showYear,
        homePage: getStore({ name: 'homePage' }) || {
            schoolId: undefined,
            schoolName: undefined,
            schoolCity: undefined,
            schoolArea: undefined,
            schoolTreeId: undefined,

            clazzId: undefined,
            clazzName: undefined,
            clazzRootId: undefined,
            clazzGrade: undefined,
            clazzTreeId: undefined,

            studentId: undefined,
            studentName: undefined,

            termValue: undefined,
            termName: undefined,

            yearValue: '' + new Date().getFullYear()
        },
    },
    mutations: {
        SET_DICT_DATA: (state, dict) => {
            state.dict = dict
            setStore({
                name: 'dict',
                content: state.dict
            })
        },
        SET_HOMEPAGE: (state, fields) => {
            // console.log("++ before", JSON.stringify(state.homePage))
            // console.log("-- fields", fields)
            state.homePage = {...state.homePage, ...fields };
            // console.log("== result", JSON.stringify(state.homePage))
            setStore({
                name: 'homePage',
                content: state.homePage,
                type: 'session'
            })
        },
        DEL_HOMEPAGE: (state) => {
            state.homePage = { yearValue: new Date().getFullYear() };
            setStore({
                name: 'homePage',
                content: state.homePage,
                type: 'session'
            })
        },
        SET_SHOWYEAR: (state, active) => {
            state.showTag = active
            setStore({
                name: 'showYear',
                content: state.showYear
            })
        },
        SET_LANGUAGE: (state, language) => {
            state.language = language
            setStore({
                name: 'language',
                content: state.language
            })
        },
        SET_COLLAPSE: (state) => {
            state.isCollapse = !state.isCollapse;
        },
        SET_IS_MENU: (state, menu) => {
            state.isMenu = menu;
        },
        SET_IS_REFRESH: (state, refresh) => {
            state.isRefresh = refresh;
        },
        SET_FULLSCREN: (state) => {
            state.isFullScren = !state.isFullScren;
        },
        SET_LOCK: (state) => {
            state.isLock = true;
            setStore({
                name: 'isLock',
                content: state.isLock,
                type: 'session'
            })
        },
        SET_SCREEN: (state, screen) => {
            state.screen = screen;
        },
        SET_COLOR_NAME: (state, colorName) => {
            state.colorName = colorName;
            setStore({
                name: 'colorName',
                content: state.colorName,
            })
        },
        SET_THEME_NAME: (state, themeName) => {
            state.themeName = themeName;
            setStore({
                name: 'themeName',
                content: state.themeName,
            })
        },
        SET_LOCK_PASSWD: (state, lockPasswd) => {
            state.lockPasswd = lockPasswd;
            setStore({
                name: 'lockPasswd',
                content: state.lockPasswd,
                type: 'session'
            })
        },
        CLEAR_LOCK: (state) => {
            state.isLock = false;
            state.lockPasswd = '';
            removeStore({
                name: 'lockPasswd',
                type: 'session'
            });
            removeStore({
                name: 'isLock',
                type: 'session'
            });
        },
    }
}
export default common